import 'package:currency_balance/bean/balance_detail.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../bean/invoice_info.dart';

class AssetsDetailPage extends StatefulWidget {
  final BalanceDetail? balanceDetail;
  final FlashBalance? flashBalanceDetail;
  final InvoiceInfo? invoiceInfo;

  const AssetsDetailPage({super.key, this.balanceDetail,this.flashBalanceDetail,this.invoiceInfo});

  @override
  State<StatefulWidget> createState() => _AssetsDetailPageState();
}

class _AssetsDetailPageState extends State<AssetsDetailPage> {
  late BalanceDetail balanceDetail;
  FlashBalance? flashBalanceDetail;
  InvoiceInfo? invoiceInfo;

  @override
  void initState() {
    balanceDetail = widget.balanceDetail!;
    flashBalanceDetail = widget.flashBalanceDetail;
    invoiceInfo = widget.invoiceInfo;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Image(image: AssetImage('assets/images/top_default_bg.png')),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding:
                    EdgeInsets.only(top: 20, right: 20, left: 20, bottom: 10),
                child: Column(
                  children: [
                    Image(
                      image: AssetImage('assets/images/app_logo.png'),
                      width: 50,
                      height: 50,
                    ),
                    SizedBox(
                      height: 30,
                    ),

                  ],
                ),
              ),
              Expanded(
                child: Container(
                  margin: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
                  padding: EdgeInsets.all(16),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(20),
                      boxShadow: [
                        BoxShadow(
                            color: Colors.grey.withOpacity(0.3),
                            offset: Offset(0, -3),
                            blurRadius: 6.0)
                      ]),
                  child: Padding(
                    padding: const EdgeInsets.all(12.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          balanceDetail.name,
                          style:
                          TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                        SizedBox(height: 6,),
                        Text(
                          '${balanceDetail.usd} \$',
                          style: TextStyle(
                              fontSize: 16, fontWeight: FontWeight.bold),
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        Text(
                          '${balanceDetail.code} ${balanceDetail.balance.toStringAsFixed(8)}',
                          style: TextStyle(color: Colors.grey),
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        Text(
                          'Price \$${balanceDetail.price}',
                          style: TextStyle(color: Colors.grey),
                        ),
                        SizedBox(
                          height: 20,
                        ),
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            QrImage(
                              data: balanceDetail.address,
                              size: 150,
                              version: QrVersions.auto,
                            ),
                            SizedBox(
                              width: 6,
                            ),
                            Expanded(
                                child: Column(
                              children: [
                                SizedBox(
                                  height: 10,
                                ),
                                Text(
                                  balanceDetail.address,
                                  style: TextStyle(color: Colors.grey),
                                ),
                                SizedBox(
                                  height: 10,
                                ),
                                SizedBox(
                                  width: 90,
                                  child: ElevatedButton(
                                      onPressed: () {
                                        Clipboard.setData(ClipboardData(text: balanceDetail.address));
                                      },
                                      style: ElevatedButton.styleFrom(backgroundColor: Colors.blue.withOpacity(0.4),shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)) ),
                                      child: Row(children: [
                                        Icon(
                                          Icons.copy,
                                          size: 12,
                                        ),
                                        SizedBox(width: 4,),
                                        Text('Copy')
                                      ])),
                                )
                              ],
                            ))
                          ],
                        ),

                        SizedBox(height: 20,),
                        if(flashBalanceDetail != null && invoiceInfo != null)
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Divider(),
                            Text(
                              'Lightning',
                              style:
                              TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                            ),
                            SizedBox(height: 6,),
                            Text(
                              '${flashBalanceDetail!.amountValue} sat',
                              style: TextStyle(
                                  fontSize: 16, fontWeight: FontWeight.bold),
                            ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  QrImage(
                                    data: invoiceInfo!.invoiceUrl,
                                    size: 150,
                                    version: QrVersions.auto,
                                  ),
                                  SizedBox(
                                    width: 6,
                                  ),
                                  Expanded(
                                      child: Column(
                                        children: [
                                          SizedBox(
                                            width: 90,
                                            child: ElevatedButton(
                                                onPressed: () {
                                                  Clipboard.setData(ClipboardData(text: invoiceInfo!.invoiceUrl));
                                                },
                                                style: ElevatedButton.styleFrom(backgroundColor: Colors.blue.withOpacity(0.4),shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)) ),
                                                child: Row(children: [
                                                  Icon(
                                                    Icons.copy,
                                                    size: 12,
                                                  ),
                                                  SizedBox(width: 4,),
                                                  Text('Copy')
                                                ])),
                                          ),
                                        ],
                                      ))
                                ],
                              ),

                          ],)
                      ],
                    ),
                  ),
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
